import express from 'express'
import multer from 'multer'
import { config } from '../config/index.js'
import {
  getDocuments,
  uploadDocument,
  vectorizeDocument,
  getDocumentContent,
  deleteDocument,
  getVectorizedContent,
  deleteVectorizedContent,
  previewDocumentChunks
} from '../controllers/documents.js'

const router = express.Router()

// 配置文件上传
const upload = multer({
  dest: config.server.upload.dir,
  limits: {
    fileSize: 150 * 1024 * 1024  // 150MB
  }
})

// 上传文档
router.post('/upload', upload.single('file'), uploadDocument)

// 具体路由放在参数路由之前
router.get('/:id/vectorized', getVectorizedContent)  // 获取向量化内容
router.post('/:id/vectorize', vectorizeDocument)     // 执行向量化
router.get('/:id/vectorize', vectorizeDocument)      // 添加 GET 方法支持 SSE
router.get('/:id/content', getDocumentContent)       // 获取文档内容
router.delete('/:id', deleteDocument)                // 删除文档
router.delete('/:id/vectorized', deleteVectorizedContent)  // 删除向量化内容
router.get('/', getDocuments)                        // 获取文档列表
router.post('/:id/preview-chunks', previewDocumentChunks)  // 添加预览分段路由

export default router 